package com.cg.design.graphicdesignpattern.observer;

import org.junit.Test;

/**
 * Observer观察者模式测试类
 *
 * @program: LeetCode->ObserverTest
 * @description: Observer观察者模式测试类
 * @author: cg
 * @create: 2022-03-29 21:42
 **/
public class ObserverTest {

    @Test
    public void testObserver() {
        System.out.println("RandomNumberGenerator:");
        NumberGenerator generator = new RandomNumberGenerator();
        Observer observer1 = new DigitObserver();
        Observer observer2 = new GraphObserver();
        Observer observer3 = new FrameObserver();
        generator.addObserver(observer1);
        generator.addObserver(observer2);
        generator.addObserver(observer3);
        generator.execute();
        System.out.println("\nIncrementalNumberGenerator:");
        NumberGenerator generator1 = new IncrementalNumberGenerator(10, 50, 5);
        generator1.addObserver(observer1);
        generator1.addObserver(observer2);
        generator1.execute();
    }

}
